<template>
  <div>
    <van-field label="机构名称" v-model="form.jigou"></van-field>
    <van-field label="客户名称" v-model="form.name"></van-field>
    <van-field label="总金额" v-model="form.tmoney"></van-field>
    客户经理<select name="" v-model="form.khjlid">
    <option v-for="i in khjl" :key="i.id" :value="i.id">{{ i.name }}</option>
  </select>
    注册名称<select name="" v-model="form.regiid">
    <option v-for="j in regi" :key="j.id" :value="j.id">{{ j.name }}</option>
  </select>
    <van-button @click="add">添加</van-button>
    <table>
      <tr>
        <td>申请人</td>
        <td>申请金额</td>
        <td>机构</td>
        <td>客户经理</td>
        <td>注册来源</td>
        <td>操作</td>
      </tr>
      <tr v-for="i in finan" :key="i.id">
        <td>{{ i.name }}</td>
        <td>{{ i.tmoney }}</td>
        <td>{{ i.jigou }}</td>
        <td>{{ i.uname }}</td>
        <td>{{ i.rname }}</td>
        <td>
          <van-button @click="dian(i.id)">审批</van-button>
        </td>
      </tr>
    </table>
    <el-dialog
        title="确认"
        v-model="dialogVisible"
        width="30%"
    >
      <span>是否同意</span>
      <el-button type="primary" @click="add_shenpi(2)">否</el-button>
      <el-button type="primary" @click="add_shenpi(1)">是</el-button>

    </el-dialog>
  </div>
</template>

<script>
import axios from 'axios'

export default {
  name: "add_kehu",
  data() {
    return {
      form: {},
      khjl: [],
      regi: [],
      finan: [],
      dialogVisible: false,
      shenpi: {'id': ''}
    }
  },
  methods: {
    get_khjl() {
      axios.get('/finan/khjl').then(res => {
        this.khjl = res.data.list
      })

    },
    get_regi() {
      axios.get('/finan/regi').then(res => {
        this.regi = res.data.list
      })

    },
    add() {
      axios.post('/finan/kehu', this.form).then(res => {
        if (res.data.code == 200) {
          alert('添加成功')
        }
      })
    },
    getfinan() {
      axios.get('http://127.0.0.1:8000/finan/').then(res => {
        if (res.data.code == 200) {
          this.finan = res.data.list
        }
      })
    },
    dian(id) {
      this.dialogVisible = true
      this.shenpi.id = id
      alert(this.shenpi.id)
    },
    add_shenpi(type) {
      axios.post('http://127.0.0.1:8000/finan/', {
        'id': this.shenpi.id,
        'type': type,
        'userid': localStorage.getItem('userid')
      }).then(res => {
        if (res.data.code == 200) {
          alert('操作成功')
        }
      })
    },

  }
  ,
  mounted() {
    this.get_khjl()
    this.get_regi()
    this.getfinan()
  }
}
</script>

<style scoped>

</style>